{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'0-10K': 16.5, '10-25K': 67.33, '25K以上': 16.17}\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/python3/lib/python3.7/site-packages/pyecharts/charts/chart.py:14: PendingDeprecationWarning: pyecharts 所有图表类型将在 v1.9.0 版本开始强制使用 ChartItem 进行数据项配置 :)\n",
      "  super().__init__(init_opts=init_opts)\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 读取文件\n",
    "df = pd.read_csv('final_jobinfo.csv')\n",
    "\n",
    "# 去除工资的单位 K\n",
    "salary = df[['最低工资','最高工资']].replace(regex={r'(\\d+)K':r'\\1'}).astype(\"float\")\n",
    "\n",
    "# 计算平均工资  axis=1 表示取列的值进行计算\n",
    "salary_avg = salary.apply(lambda item: (item['最低工资'] + item['最高工资'])/2, axis=1)\n",
    "\n",
    "# 将数据分成三个挡位  0- 10K  10 - 25K  25K 以上\n",
    "salary_dic = {'0-10K':0,'10-25K':0,'25K以上':0}\n",
    "for i in salary_avg:\n",
    "    if( 0<= i <= 10):\n",
    "        salary_dic['0-10K']  += 1 \n",
    "    elif( 10< i <= 25):\n",
    "        salary_dic['10-25K'] += 1 \n",
    "    else:\n",
    "        salary_dic['25K以上'] += 1\n",
    "\n",
    "# 岗位总数量\n",
    "count = 0\n",
    "for value in salary_dic.values():\n",
    "    count += value\n",
    "\n",
    "# 转换为百分比\n",
    "for key in salary_dic.keys():\n",
    "    value = (salary_dic[key] / count)*100\n",
    "    salary_dic[key] = float(\"%.2f\" %(value))\n",
    "\n",
    "print(salary_dic)\n",
    "# # 生成饼图\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Pie\n",
    "\n",
    "c = (\n",
    "    Pie()\n",
    "    .add(\"\", [list(z) for z in zip(salary_dic.keys(),salary_dic.values())])\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"大数据岗位薪资水平分布\"))\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}: {c}%\"))\n",
    "    .render(\"大数据岗位薪资水平分布.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/python3/lib/python3.7/site-packages/pyecharts/charts/chart.py:14: PendingDeprecationWarning: pyecharts 所有图表类型将在 v1.9.0 版本开始强制使用 ChartItem 进行数据项配置 :)\n",
      "  super().__init__(init_opts=init_opts)\n",
      "/usr/local/python3/lib/python3.7/site-packages/pyecharts/charts/chart.py:14: PendingDeprecationWarning: pyecharts 所有图表类型将在 v1.9.0 版本开始强制使用 ChartItem 进行数据项配置 :)\n",
      "  super().__init__(init_opts=init_opts)\n",
      "/usr/local/python3/lib/python3.7/site-packages/pyecharts/charts/composite_charts/grid.py:17: PendingDeprecationWarning: pyecharts 所有图表类型将在 v1.9.0 版本开始强制使用 ChartItem 进行数据项配置 :)\n",
      "  super().__init__(init_opts=init_opts)\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Pie, Bar, Grid\n",
    "# 读取文件\n",
    "data = pd.read_csv('final_jobinfo.csv')\n",
    "\n",
    "companys = []\n",
    "values = []\n",
    "counts = []\n",
    "# 统计公司类型数量，按照公司类型进行分组统计\n",
    "data = data['公司类型'].groupby(data['公司类型']).value_counts()\n",
    "for key, value in zip(data.keys(), data.values):\n",
    "    # print(key[0])\n",
    "    # print(value)\n",
    "    companys.append(key[0].strip())\n",
    "    counts.append(int(value))\n",
    "    values.append(\"%.1f\" % ((int(value) / data.values.sum()) * 100))\n",
    "\n",
    "pie = (\n",
    "    Pie().add(\"公司类型统计\",[list(z) for z in zip(companys, values)],\n",
    "        center=[\"25%\", \"50%\"],)\n",
    "        .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"公司类型统计\",pos_left=\"25%\"),\n",
    "        legend_opts=opts.LegendOpts(is_show=False),)\n",
    "        .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}:{c}%\"))\n",
    ")\n",
    "\n",
    "bar = (\n",
    "    Bar()\n",
    "        .add_xaxis(companys)\n",
    "        .add_yaxis(\"数量\", counts)\n",
    "        .set_global_opts(legend_opts=opts.LegendOpts(pos_right=\"20%\"))\n",
    "        .reversal_axis()\n",
    "        .set_series_opts(label_opts=opts.LabelOpts(position=\"right\"))\n",
    ")\n",
    "\n",
    "# 将饼图和柱状图合并成一个图形\n",
    "grid = (\n",
    "    Grid(init_opts=opts.InitOpts(width=\"1800px\", height=\"720px\"))\n",
    "        .add(bar, grid_opts=opts.GridOpts(pos_left=\"68%\"), is_control_axis_index=True)\n",
    "        .add(pie, grid_opts=opts.GridOpts(pos_right=\"40%\"), is_control_axis_index=True)\n",
    "        .render(\"公司类型和数量占比统计.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/python3/lib/python3.7/site-packages/pyecharts/charts/chart.py:14: PendingDeprecationWarning: pyecharts 所有图表类型将在 v1.9.0 版本开始强制使用 ChartItem 进行数据项配置 :)\n",
      "  super().__init__(init_opts=init_opts)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'/pydir/py_project/pythonCode/深圳岗位分布数量图.html'"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Map\n",
    "data = pd.read_csv('final_jobinfo.csv')\n",
    "# 将类似深圳-罗湖区的数据以 - 切分为两列\n",
    "data[['地区','区']] = data['地区'].str.split('-',expand=True)\n",
    "\n",
    "# 按地区进行分组统计，统计每个区招聘岗位的数量\n",
    "data = data['地区'].groupby(data['区']).value_counts()\n",
    "areas = []\n",
    "values = []\n",
    "\n",
    "for key,value in zip(data.keys(),data.values):\n",
    "    # 去除深圳地区以外的招聘信息\n",
    "    if key[1] == '深圳':\n",
    "        area = key[0].strip()\n",
    "        if \"龙华\" in key[0]:\n",
    "            area = '龙华区'\n",
    "        areas.append(area)\n",
    "        values.append(int(value))\n",
    "\n",
    "map = Map()\n",
    "map.add(\"招聘人数\", [list(z) for z in zip(areas, values)], \"深圳\")\n",
    "map.set_global_opts(title_opts=opts.TitleOpts(title=\"深圳大数据岗位分布数量图\"),\n",
    "visualmap_opts=opts.VisualMapOpts(max_=800, range_color=[\"lightskyblue\", \"yellow\", \"orangered\"],is_piecewise=True),tooltip_opts=opts.TooltipOpts(is_show=True))\n",
    "map.render(path = '深圳岗位分布数量图.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'dict_values' object is not callable",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-74-56b33b39430a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: 'dict_values' object is not callable"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
